//package cn.mesmile.shiro.module.session.controller;
//
//import cn.hutool.core.date.DateUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.session.Session;
//import org.apache.shiro.session.mgt.SessionKey;
//import org.apache.shiro.session.mgt.eis.SessionDAO;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.Serializable;
//import java.util.Collection;
//import java.util.Date;
//
///**
// * @author zb
// * @date 2021/2/19 18:04
// * @Description
// */
//@Slf4j
//@RestController
//public class SessionController {
//
////    @Autowired
////    private SessionDAO sessionDAO;
//
//    @RequestMapping("/session/list")
//    public String list() {
//        Collection<Session> sessions = sessionDAO.getActiveSessions();
//        for (Session session : sessions) {
//            Serializable id = session.getId();
//            String host = session.getHost();
//            Date lastAccessTime = session.getLastAccessTime();
//            Object username = session.getAttribute("username");
//            if (username != null){
//                System.out.println("id = " + id.toString());
//                System.out.println("lastAccessTime = " + DateUtil.formatDateTime(lastAccessTime));
//                System.out.println("username.toString() = " + username.toString());
//            }
//        }
//        return "sessions/list";
//    }
//
//
//    /**
//     * 强制退出
//     * @return
//     */
//    @GetMapping("/session/forceLogout/{token}")
//    public String forceLogout(HttpServletRequest request, @PathVariable("token")String token) {
//        try {
////            Session session = readSessionDAO.readSession(token);
//            SessionKey sessionKey = new SessionKey() {
//                @Override
//                public Serializable getSessionId() {
//                    return token;
//                }
//            };
//            SecurityManager securityManager = SecurityUtils.getSecurityManager();
//            Session session = securityManager.getSession(sessionKey);
//
//            if(session != null) {
//                session.setAttribute("SESSION_FORCE_LOGOUT_KEY", Boolean.TRUE);
//            }
//        } catch (Exception e) {
//            /*忽略*/
//        }
//        return "redirect:/sessions";
//    }
//
//
//}
